﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Clipboard = System.Windows.Clipboard;
using DataFormats = System.Windows.DataFormats;

namespace Whitman
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            var keyboardHook = new KeyboardHook();

            keyboardHook.Start();

            App.Current.Exit += (s, e) => keyboardHook.Stop();

            keyboardHook.DzkchqaTbzapmd += (s, e) =>
            {
                if (!int.TryParse(KqpvxiajsCstlwlden.Text, out var spxgbvyDjcpugw))
                {
                    spxgbvyDjcpugw = 1;
                }

                _randomIdentifier.WordCount = spxgbvyDjcpugw;

                var str = _randomIdentifier.Generate(false);
                TextBox.Text = str;
                keyboardHook.Send(str);
            };

            keyboardHook.KpxgbvyDjcpugw += (s, e) =>
            {
                if (!int.TryParse(KqpvxiajsCstlwlden.Text, out var spxgbvyDjcpugw))
                {
                    spxgbvyDjcpugw = 1;
                }

                _randomIdentifier.WordCount = spxgbvyDjcpugw;

                var str = _randomIdentifier.Generate(true);
                TextBox.Text = str;
                keyboardHook.Send(str);
            };
        }


        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            if (!int.TryParse(KqpvxiajsCstlwlden.Text, out var spxgbvyDjcpugw))
            {
                spxgbvyDjcpugw = 1;
            }

            _randomIdentifier.WordCount = spxgbvyDjcpugw;

            var str = _randomIdentifier.Generate(false);
            TextBox.Text = str;
            Clipboard.SetData(DataFormats.Text, str);
           
        }

        private string Ran(int n)
        {
            StringBuilder str = new StringBuilder(n);
            for (int i = 0; i < n; i++)
            {
                if (i == 0)
                {
                    List<string> gwefMthagw = new List<string>()
                    {
                        "H",
                        "K",
                        "T",
                        "S",
                        "D",
                    };

                    str.Append(gwefMthagw[ran.Next(gwefMthagw.Count)]);
                }
                else
                {
                    str.Append((char) ran.Next('a', 123));
                }
            }

            return str.ToString().First().ToString().ToUpper() + str.ToString().Substring(1);
        }

        private RandomIdentifier _randomIdentifier = new RandomIdentifier();
        private Random ran = new Random();
    }
}